<template>

   <div>
      欢迎 {{username}}登录<br/>
       <router-link to="tushu4">购物车</router-link>
<div v-for="i in li" :key="i.id">
            <p>{{i.title}}---<button @click="jia(i.id)">加入购物车</button></p> 
            <li v-for='i in i.books' :key="i.id">
                <router-link :to="{path:'tushu3',query:{id:i.id}}">{{i.title}}</router-link>---<button @click="jia(i.id)">加入购物车</button>
            </li>
        </div>
   </div>

</template>

<script>
import Axios from 'axios'
export default {
   data(){
       return {
           li:[],
           book:[],
           username:sessionStorage.getItem('username'),
           token:sessionStorage.getItem('token'),
       }
   },
   methods:{
       jia(x){
           Axios.post('http://127.0.0.1:8000/che/che?token='+this.token,{'pid':x,'num':1}).then(resp=>{
               console.log(resp.data)
               if (resp.data.code==200){
                   alert(resp.data.msg)
               }else{
                   alert(resp.data.msg)
               }
           })
       }
   },
   created(){//分类展示
       Axios.get('http://127.0.0.1:8000/cate/cate').then(resp=>{
           console.log(resp)
           this.li=resp.data
       })
   
   }
}
</script>

<style>

</style>